using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using IGlobalist.Cms.Common;
using IGlobalist.Cms.Model;
using IGlobalist.Cms.Bll;
namespace IGlobalist.Cms.Admin.Control
{
    public partial class ResourceFolderList : AdminBaseUserControl 
    {
        public event EventHandler EventEditResourceFolder;
        public event EventHandler EventDoHidden;
        
        protected void Page_Load(object sender, EventArgs e)
        {

        }


        public void DoBindResourceFolder(object sender, EventArgs e)
        {
            ClassList ucClassList = (ClassList)sender;
            BindForm(Convert.ToInt64(ucClassList.SelectedValue));
        }

        public void BindForm(long classID)
        {
            try
            {
                Session[SessionVariable.Clazz.CurrentID] = classID;
                ICmsClass clazz = ClassController.GetClass(classID);
                if (clazz != null)
                {
                    gvResourceFolder.DataSource = ResourceFolderController.GetResourceFolderList(classID);
                    gvResourceFolder.DataBind();
                }
            }
            catch (Exception ex)
            {
                Logger.Error("[[ResourceFolderList]]", ex);
            }
        }
              

        public void DoHidden(object sender, EventArgs e)
        {
            this.Visible = false;
        }

        public void DoShow(object sender, EventArgs e)
        {
            this.Visible = true;
            if (EventDoHidden != null)
                EventDoHidden(this, new EventArgs());
            BindForm(Convert.ToInt64(Session[SessionVariable.Clazz.CurrentID]));
        }

        public string SelectedReFolderID
        {
            get { return (string)ViewState["RefolderID"]; }
            set { ViewState["RefolderID"] = value; }
        }

        protected void ibEdit_Click(object sender, ImageClickEventArgs e)
        {
            ImageButton ib = (ImageButton)sender;
            SelectedReFolderID = ib.CommandArgument; 
            if (EventEditResourceFolder!= null)
            {
                EventEditResourceFolder(this, new EventArgs());
            }            
        }

        protected void ibDelete_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                ImageButton ib = (ImageButton)sender;
                ResourceFolderController.DeleteResourceFolder(Convert.ToInt64(ib.CommandArgument));
                BindForm(Convert.ToInt64(Session[SessionVariable.Clazz.CurrentID]));
            }
            catch (Exception ex)
            {
                Logger.Error("[[ResourceFolderList]]", ex);
            }
        }   
    }
}